//
//  YSGMyopiaEyeVisionCell.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2021/1/7.
//  Copyright © 2021 QDSG. All rights reserved.
//

import UIKit

class YSGMyopiaEyeVisionCell: UITableViewCell, UITextFieldDelegate {
    
    weak var delegate: YSGMyopiaRecordCellDelegate?
    
    private var checkInfo = YSGMyopiaRecordDetailCheckInfo()

    func configure(with checkInfo: YSGMyopiaRecordDetailCheckInfo, isEdited: Bool) {
        self.checkInfo = checkInfo
        titleLabel.text = checkInfo.title
        visionTextField.text = checkInfo.eyeVision
        visionTextField.isEnabled = !isEdited
    }
    
    @IBOutlet private weak var containerView: UIView! {
        didSet {
            containerView.layer.cornerRadius = containerView.height / 2
            containerView.setShadow()
        }
    }
    
    @IBOutlet private weak var titleLabel: UILabel!
    
    @IBOutlet private weak var visionTextField: UITextField! {
        didSet {
            visionTextField.delegate = self
        }
    }
    
    func textFieldDidEndEditing(_ textField: UITextField) {
        checkInfo.eyeVision = textField.text
        
        delegate?.eyeVisionCell(self, checkInfo: checkInfo)
    }
}
